#include "gameobject.h"

GameObject::GameObject(Game* game) {
    this->game = game;
    this->position = Vector4(0, 0, 0, 1);
    this->rotation = Vector4(0, 0, 0, 1);
    this->scale = 1;
    this->worldMatrix = Matrix4x4::IDENTITY;
    this->worldMatrixNeedsUpdate = true;
}

GameObject::~GameObject(void) {
}

Game* GameObject::GetGame() const {
    return this->game;
}

Vector4 GameObject::GetPosition() const {
    return this->position;
}

void GameObject::SetPosition(Vector4 val) {
    this->position = val;
    this->worldMatrixNeedsUpdate = true;
}

Vector4 GameObject::GetRotation() const {
    return this->rotation;
}

void GameObject::SetRotation(Vector4 val) {
    this->rotation = val;
    this->worldMatrixNeedsUpdate = true;
}

float GameObject::GetScale() const {
    return this->scale;
}

void GameObject::SetScale(float val) {
    this->scale = val;
    this->worldMatrixNeedsUpdate = true;
}

Matrix4x4 GameObject::GetWorldMatrix() {
    if (!this->worldMatrixNeedsUpdate) {
        return this->worldMatrix;
    }

    Matrix4x4 matTrans, matScale, matRotX, matRotY, matRotZ;
    matTrans.Translation(this->position.x, this->position.y, this->position.z);
    matRotX.RotationX(this->rotation.x);
    matRotY.RotationY(this->rotation.y);
    matRotZ.RotationZ(this->rotation.z);
    matScale.Scaling(this->scale);

    Matrix4x4 rotationMatrix = matRotZ * matRotY * matRotX;
    this->worldMatrix = rotationMatrix * matScale * matTrans;
    this->worldMatrixNeedsUpdate = false;
    return this->worldMatrix;
}

void GameObject::Draw(float timeDelta) {
}

void GameObject::Draw(Matrix4x4 matrix) {
}

void GameObject::Initialize() {
}

void GameObject::LoadContent() {
}

void GameObject::UnloadContent() {
}

void GameObject::Update(float timeDelta) {
}
